print('1.函数的定义和调用')
def calc(a,b): #a，b是：形式参数(形参)
    c = a + b
    return c
t = calc(10,20) #10,20称为实参值，按顺序赋值
print(t)
res = calc(a = 20, b = 10) #左侧的变量的名称叫: 关键字参数，就不按照顺序去赋值
print(res)
print()

print(2)
def fun(arg1, arg2):
    print('arg1', arg1)
    print('arg2', arg2)
    arg1 = 100
    arg2.append(100)
    print('arg1', arg1)
    print('arg2', arg2)
n1 = 11
n2 = [22, 33, 44]
fun(n1, n2)
print()

print('3.函数的返回值')
def fun(num):
    odd = [] #存奇数
    even = [] #存偶数
    for i in num:
        if i % 2 == 0:
            even.append(i)
        else:
            odd.append(i)
    return odd, even
lst = [100,56,57,32,41,47,33]
print(fun(lst))
print()

print('4.参数传值')
def fun(a, b = 10):
    print(a,b)
fun(100)
fun(10,30)
print()

print('5.个数可变的位置*args')
def fun(*args):
    print(args)
fun(10)
fun(20,30)
fun(40,50,60)
print()

print('6.**args形参的结果为字典')
def fun(**args):
    print(args)
fun(a = 10)
fun(b = 10, c = 20, d = 30)
print()

print('7.参数传值')
def fun(a,b,c):
    print("a =", a)
    print("b =", b)
    print("c =", c)
lst = [11,22,33]
fun(*lst)
str = {'a':100, 'b':200, 'c':300}
print(fun(**str))

